define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'ykjp/summary/purchase/index' + location.search,
                    table: 'storage',
                }
            });

            var table = $("#table");
            //当表格数据加载完成时
            table.on('load-success.bs.table', function (e, data) {
                $("#totalNums").text(data.extend.totalNums);
                $("#money").text(data.extend.totalMoney);
            });


            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                searchFormTemplate: 'customformtpl',
                // searchFormVisible: true,
                // commonSearch:false,
                search: false,
                exportTypes: ['excel'],
                columns: [
                    [
                        {checkbox: true},
                        {field: 'storage.code', title: __('Code')},
                        {field: 'productName', title: __('ProductName')},
                        {field: 'supplier', title: __('Supplier')},
                        {field: 'warehouse', title: __('Warehouse')},
                        {field: 'partition', title: __('Partition')},
                        {field: 'price', title: __('Price'), operate: false},
                        {field: 'nums', title: __('Nums'), operate: false},
                        {field: 'subtotal', title: __('Subtotal'), operate: false},
                        {field: 'storage.inbound_type', title: __('Inbound_type'), formatter: function (e, row) {
                                console.log(row.storage.inbound_type)
                                var a = row.storage.inbound_type;
                                if (a == 0) {
                                    b = __('Inbound_type 0');
                                } else {
                                    b = __('Inbound_type 1');
                                }
                                return b;
                            }},
                        {field: 'createtime', title: __('Createtime'), operate: 'RANGE', addclass: 'datetimerange', formatter: Table.api.formatter.datetime, datetimeFormat: "YYYY-MM-DD"},
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});




